import cache from './cache'
import { useUserStore } from './stores/modules/user'
import { TOKEN_KEY } from '@/utils/enums/cacheEnums'
import { resetRouter } from '@/utils/router'

export function getToken(): string {
    return cache.get(TOKEN_KEY) || ''
}

export function setToken(token: string): void {
    cache.set(TOKEN_KEY, token)
}

export function removeToken(): void {
    cache.remove(TOKEN_KEY)
}

export function clearAuthInfo() {
    const userStore = useUserStore()
    cache.remove(TOKEN_KEY)
    userStore.$reset()
    resetRouter()
}